package remoto;

import hbt.HibernateUtil;

import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class BS {
	
	public static void main(String[] args) {
		System.out.println(IGestion.class.toString());
		System.out.println(IGestion.class.getProtectionDomain().getCodeSource().getLocation().toString());
		
		System.setProperty("java.rmi.server.codebase", IGestion.class.getProtectionDomain().getCodeSource().getLocation().toString());
	  	
		new BS().publicarServicio();
		HibernateUtil.getSessionFactory();
			
		//	load();
	}
    
    public void publicarServicio() {
    	try {
    		Remote gestion = GestionImpl.getInstance();
    		IGestion stub = (IGestion) UnicastRemoteObject.exportObject(gestion, 0);
			LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
			Naming.rebind("//localhost/Gestion", stub);
            verVinculos();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public void verVinculos() {
        try {
      	  String[] vinculos = Naming.list( "" );
      	  System.out.println(InetAddress.getLocalHost().getHostAddress());
      	  for ( int i = 0; i < vinculos.length; i++ ){
      		System.out.print( "\n"+vinculos[i] );
      	  }
        }
        catch (Exception e) {
      	  e.printStackTrace();
        }
     }

}
